/* @refresh reload */
import { render } from "solid-js/web";
import { Router } from "@solidjs/router";
import { lazy } from "solid-js";
import App from "./App";
import { initServerConfig } from "./lib/api/server";

const routes = {
  path: "/",
  component: App,
  children: [
    {
      path: "/",
      component: lazy(() => import("./features/home/Home")),
    },
    {
      path: "/collections",
      component: lazy(() => import("./features/collection/Collections")),
    },
    {
      path: "/collectionDetail/:id",
      component: lazy(() => import("./features/collection/CollectionDetail")),
    },
    {
      path: "/downloads",
      component: lazy(() => import("./features/downloads/Downloads")),
    },
    {
      path: "/categories/:id",
      component: lazy(() => import("./features/categories/Categories")),
    },
    {
      path: "/app/:category/:pkgname",
      component: lazy(() => import("./features/app-detail/AppDetail")),
    },
    {
      path: "/search",
      component: lazy(() => import("./features/search/Search")),
    },
  ],
};

// 初始化应用
const init = async () => {
  document.addEventListener('contextmenu', event => event.preventDefault());

  // 等待服务器配置初始化完成
  await initServerConfig();
  
  // 渲染应用
  render(
    () => <Router>{routes}</Router>,
    document.getElementById("root") as HTMLElement
  );
};

init().catch(console.error);
